
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>函数 · TypeScript Handbook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Patrick Zhong">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Generics.html" />
    
    
    <link rel="prev" href="Classes.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="tutorials/">
            
                <a href="tutorials/">
            
                    
                    快速上手
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="tutorials/TypeScript in 5 minutes.html">
            
                <a href="tutorials/TypeScript in 5 minutes.html">
            
                    
                    5分钟了解TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="tutorials/ASP.NET Core.html">
            
                <a href="tutorials/ASP.NET Core.html">
            
                    
                    ASP.NET Core
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="tutorials/ASP.NET 4.html">
            
                <a href="tutorials/ASP.NET 4.html">
            
                    
                    ASP.NET 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="tutorials/Gulp.html">
            
                <a href="tutorials/Gulp.html">
            
                    
                    Gulp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="tutorials/Knockout.html">
            
                <a href="tutorials/Knockout.html">
            
                    
                    Knockout.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="tutorials/React & Webpack.html">
            
                <a href="tutorials/React & Webpack.html">
            
                    
                    React与webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="tutorials/React.html">
            
                <a href="tutorials/React.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="tutorials/Angular 2.html">
            
                <a href="tutorials/Angular 2.html">
            
                    
                    Angular 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="tutorials/Migrating from JavaScript.html">
            
                <a href="tutorials/Migrating from JavaScript.html">
            
                    
                    从JavaScript迁移到TypeScript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    手册
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="Basic Types.html">
            
                <a href="Basic Types.html">
            
                    
                    基础类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Variable Declarations.html">
            
                <a href="Variable Declarations.html">
            
                    
                    变量声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="Interfaces.html">
            
                <a href="Interfaces.html">
            
                    
                    接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="Classes.html">
            
                <a href="Classes.html">
            
                    
                    类
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.5" data-path="Functions.html">
            
                <a href="Functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="Generics.html">
            
                <a href="Generics.html">
            
                    
                    泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="Enums.html">
            
                <a href="Enums.html">
            
                    
                    枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="Type Inference.html">
            
                <a href="Type Inference.html">
            
                    
                    类型推论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="Type Compatibility.html">
            
                <a href="Type Compatibility.html">
            
                    
                    类型兼容性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="Advanced Types.html">
            
                <a href="Advanced Types.html">
            
                    
                    高级类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="Utilit Types.md">
            
                <span>
            
                    
                    实用工具类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="Symbols.html">
            
                <a href="Symbols.html">
            
                    
                    Symbols
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="Iterators and Generators.html">
            
                <a href="Iterators and Generators.html">
            
                    
                    Iterators 和 Generators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="Modules.html">
            
                <a href="Modules.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.15" data-path="Namespaces.html">
            
                <a href="Namespaces.html">
            
                    
                    命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.16" data-path="Namespaces and Modules.html">
            
                <a href="Namespaces and Modules.html">
            
                    
                    命名空间和模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.17" data-path="Module Resolution.html">
            
                <a href="Module Resolution.html">
            
                    
                    模块解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.18" data-path="Declaration Merging.html">
            
                <a href="Declaration Merging.html">
            
                    
                    声明合并
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.19" data-path="Writing Definition Files.html">
            
                <a href="Writing Definition Files.html">
            
                    
                    书写.d.ts文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.20" data-path="JSX.html">
            
                <a href="JSX.html">
            
                    
                    JSX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.21" data-path="Decorators.html">
            
                <a href="Decorators.html">
            
                    
                    Decorators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.22" data-path="Mixins.html">
            
                <a href="Mixins.html">
            
                    
                    混入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.23" data-path="Triple-Slash Directives.html">
            
                <a href="Triple-Slash Directives.html">
            
                    
                    三斜线指令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.24" data-path="Type Checking JavaScript Files.html">
            
                <a href="Type Checking JavaScript Files.html">
            
                    
                    JavaScript文件里的类型检查
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="declaration files/Introduction.html">
            
                <a href="declaration files/Introduction.html">
            
                    
                    如何书写声明文件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="declaration files/Library Structures.html">
            
                <a href="declaration files/Library Structures.html">
            
                    
                    结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="declaration files/Do's and Don'ts.html">
            
                <a href="declaration files/Do's and Don'ts.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="declaration files/By Example.html">
            
                <a href="declaration files/By Example.html">
            
                    
                    举例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="declaration files/Deep Dive.html">
            
                <a href="declaration files/Deep Dive.html">
            
                    
                    深入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="declaration files/Publishing.html">
            
                <a href="declaration files/Publishing.html">
            
                    
                    发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="declaration files/Consumption.html">
            
                <a href="declaration files/Consumption.html">
            
                    
                    使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    工程配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    tsconfig.json
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="Project References.html">
            
                <a href="Project References.html">
            
                    
                    工程引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Typings for NPM Packages.html">
            
                <a href="Typings for NPM Packages.html">
            
                    
                    NPM包的类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="Compiler Options.html">
            
                <a href="Compiler Options.html">
            
                    
                    编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Configuring Watch.html">
            
                <a href="Configuring Watch.html">
            
                    
                    配置 Watch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="Compiler Options in MSBuild.html">
            
                <a href="Compiler Options in MSBuild.html">
            
                    
                    在MSBuild里使用编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="Integrating with Build Tools.html">
            
                <a href="Integrating with Build Tools.html">
            
                    
                    与其它构建工具整合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="Nightly Builds.html">
            
                <a href="Nightly Builds.html">
            
                    
                    使用TypeScript的每日构建版本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../wiki/">
            
                <a href="../wiki/">
            
                    
                    Wiki
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../wiki/this-in-TypeScript.html">
            
                <a href="../wiki/this-in-TypeScript.html">
            
                    
                    TypeScript里的this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../wiki/coding_guidelines.html">
            
                <a href="../wiki/coding_guidelines.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../wiki/Common Errors.html">
            
                <a href="../wiki/Common Errors.html">
            
                    
                    常见编译错误
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../wiki/TypeScript-Editor-Support.html">
            
                <a href="../wiki/TypeScript-Editor-Support.html">
            
                    
                    支持TypeScript的编辑器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                <a href="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                    
                    结合ASP.NET v5使用TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../wiki/Architectural-Overview.html">
            
                <a href="../wiki/Architectural-Overview.html">
            
                    
                    架构概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../wiki/Roadmap.html">
            
                <a href="../wiki/Roadmap.html">
            
                    
                    发展路线图
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../release-notes/">
            
                <a href="../release-notes/">
            
                    
                    新增功能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../release-notes/TypeScript 3.1.html">
            
                <a href="../release-notes/TypeScript 3.1.html">
            
                    
                    TypeScript 3.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../release-notes/TypeScript 3.0.html">
            
                <a href="../release-notes/TypeScript 3.0.html">
            
                    
                    TypeScript 3.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../release-notes/TypeScript 2.9.html">
            
                <a href="../release-notes/TypeScript 2.9.html">
            
                    
                    TypeScript 2.9
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../release-notes/TypeScript 2.8.html">
            
                <a href="../release-notes/TypeScript 2.8.html">
            
                    
                    TypeScript 2.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../release-notes/TypeScript 2.7.html">
            
                <a href="../release-notes/TypeScript 2.7.html">
            
                    
                    TypeScript 2.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../release-notes/TypeScript 2.6.html">
            
                <a href="../release-notes/TypeScript 2.6.html">
            
                    
                    TypeScript 2.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../release-notes/TypeScript 2.5.html">
            
                <a href="../release-notes/TypeScript 2.5.html">
            
                    
                    TypeScript 2.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../release-notes/TypeScript 2.4.html">
            
                <a href="../release-notes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../release-notes/TypeScript 2.3.html">
            
                <a href="../release-notes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../release-notes/TypeScript 2.2.html">
            
                <a href="../release-notes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.11" data-path="../release-notes/TypeScript 2.1.html">
            
                <a href="../release-notes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.12" data-path="../release-notes/TypeScript 2.0.html">
            
                <a href="../release-notes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.13" data-path="../release-notes/TypeScript 1.8.html">
            
                <a href="../release-notes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.14" data-path="../release-notes/TypeScript 1.7.html">
            
                <a href="../release-notes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.15" data-path="../release-notes/TypeScript 1.6.html">
            
                <a href="../release-notes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.16" data-path="../release-notes/TypeScript 1.5.html">
            
                <a href="../release-notes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.17" data-path="../release-notes/TypeScript 1.4.html">
            
                <a href="../release-notes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.18" data-path="../release-notes/TypeScript 1.3.html">
            
                <a href="../release-notes/TypeScript 1.3.html">
            
                    
                    TypeScript 1.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.19" data-path="../release-notes/TypeScript 1.1.html">
            
                <a href="../release-notes/TypeScript 1.1.html">
            
                    
                    TypeScript 1.1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../breaking-changes/breaking-changes.html">
            
                <a href="../breaking-changes/breaking-changes.html">
            
                    
                    Breaking Changes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../breaking-changes/TypeScript 2.4.html">
            
                <a href="../breaking-changes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../breaking-changes/TypeScript 2.3.html">
            
                <a href="../breaking-changes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../breaking-changes/TypeScript 2.2.html">
            
                <a href="../breaking-changes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../breaking-changes/TypeScript 2.1.html">
            
                <a href="../breaking-changes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../breaking-changes/TypeScript 2.0.html">
            
                <a href="../breaking-changes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../breaking-changes/TypeScript 1.8.html">
            
                <a href="../breaking-changes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../breaking-changes/TypeScript 1.7.html">
            
                <a href="../breaking-changes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../breaking-changes/TypeScript 1.6.html">
            
                <a href="../breaking-changes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../breaking-changes/TypeScript 1.5.html">
            
                <a href="../breaking-changes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="../breaking-changes/TypeScript 1.4.html">
            
                <a href="../breaking-changes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >函数</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4ECB;&#x7ECD;">&#x4ECB;&#x7ECD;</h1>
<p>&#x51FD;&#x6570;&#x662F;JavaScript&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x57FA;&#x7840;&#x3002;
&#x5B83;&#x5E2E;&#x52A9;&#x4F60;&#x5B9E;&#x73B0;&#x62BD;&#x8C61;&#x5C42;&#xFF0C;&#x6A21;&#x62DF;&#x7C7B;&#xFF0C;&#x4FE1;&#x606F;&#x9690;&#x85CF;&#x548C;&#x6A21;&#x5757;&#x3002;
&#x5728;TypeScript&#x91CC;&#xFF0C;&#x867D;&#x7136;&#x5DF2;&#x7ECF;&#x652F;&#x6301;&#x7C7B;&#xFF0C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x548C;&#x6A21;&#x5757;&#xFF0C;&#x4F46;&#x51FD;&#x6570;&#x4ECD;&#x7136;&#x662F;&#x4E3B;&#x8981;&#x7684;&#x5B9A;&#x4E49;<em>&#x884C;&#x4E3A;</em>&#x7684;&#x5730;&#x65B9;&#x3002;
TypeScript&#x4E3A;JavaScript&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x4E86;&#x989D;&#x5916;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x66F4;&#x5BB9;&#x6613;&#x5730;&#x4F7F;&#x7528;&#x3002;</p>
<h1 id="&#x51FD;&#x6570;">&#x51FD;&#x6570;</h1>
<p>&#x548C;JavaScript&#x4E00;&#x6837;&#xFF0C;TypeScript&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x6709;&#x540D;&#x5B57;&#x7684;&#x51FD;&#x6570;&#x548C;&#x533F;&#x540D;&#x51FD;&#x6570;&#x3002;
&#x4F60;&#x53EF;&#x4EE5;&#x968F;&#x610F;&#x9009;&#x62E9;&#x9002;&#x5408;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x4E0D;&#x8BBA;&#x662F;&#x5B9A;&#x4E49;&#x4E00;&#x7CFB;&#x5217;API&#x51FD;&#x6570;&#x8FD8;&#x662F;&#x53EA;&#x4F7F;&#x7528;&#x4E00;&#x6B21;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x53EF;&#x4EE5;&#x8FC5;&#x901F;&#x56DE;&#x60F3;&#x8D77;&#x8FD9;&#x4E24;&#x79CD;JavaScript&#x4E2D;&#x7684;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-comment">// Named function</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">x, y</span>) </span>{
    <span class="hljs-keyword">return</span> x + y;
}

<span class="hljs-comment">// Anonymous function</span>
<span class="hljs-keyword">let</span> myAdd = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">x, y</span>) </span>{ <span class="hljs-keyword">return</span> x + y; };
</code></pre>
<p>&#x5728;JavaScript&#x91CC;&#xFF0C;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x4F53;&#x5916;&#x90E8;&#x7684;&#x53D8;&#x91CF;&#x3002;
&#x5F53;&#x51FD;&#x6570;&#x8FD9;&#x4E48;&#x505A;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x8BF4;&#x5B83;&#x2018;&#x6355;&#x83B7;&#x2019;&#x4E86;&#x8FD9;&#x4E9B;&#x53D8;&#x91CF;&#x3002;
&#x81F3;&#x4E8E;&#x4E3A;&#x4EC0;&#x4E48;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#x505A;&#x4EE5;&#x53CA;&#x5176;&#x4E2D;&#x7684;&#x5229;&#x5F0A;&#x8D85;&#x51FA;&#x4E86;&#x672C;&#x6587;&#x7684;&#x8303;&#x56F4;&#xFF0C;&#x4F46;&#x662F;&#x6DF1;&#x523B;&#x7406;&#x89E3;&#x8FD9;&#x4E2A;&#x673A;&#x5236;&#x5BF9;&#x5B66;&#x4E60;JavaScript&#x548C;TypeScript&#x4F1A;&#x5F88;&#x6709;&#x5E2E;&#x52A9;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> z = <span class="hljs-number">100</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addToZ</span>(<span class="hljs-params">x, y</span>) </span>{
    <span class="hljs-keyword">return</span> x + y + z;
}
</code></pre>
<h1 id="&#x51FD;&#x6570;&#x7C7B;&#x578B;">&#x51FD;&#x6570;&#x7C7B;&#x578B;</h1>
<h2 id="&#x4E3A;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x7C7B;&#x578B;">&#x4E3A;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x7C7B;&#x578B;</h2>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x4E3A;&#x4E0A;&#x9762;&#x90A3;&#x4E2A;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x7C7B;&#x578B;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">x: <span class="hljs-built_in">number</span>, y: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">number</span> </span>{
    <span class="hljs-keyword">return</span> x + y;
}

<span class="hljs-keyword">let</span> myAdd = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">x: <span class="hljs-built_in">number</span>, y: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">number</span> </span>{ <span class="hljs-keyword">return</span> x + y; };
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7ED9;&#x6BCF;&#x4E2A;&#x53C2;&#x6570;&#x6DFB;&#x52A0;&#x7C7B;&#x578B;&#x4E4B;&#x540E;&#x518D;&#x4E3A;&#x51FD;&#x6570;&#x672C;&#x8EAB;&#x6DFB;&#x52A0;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x3002;
TypeScript&#x80FD;&#x591F;&#x6839;&#x636E;&#x8FD4;&#x56DE;&#x8BED;&#x53E5;&#x81EA;&#x52A8;&#x63A8;&#x65AD;&#x51FA;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x901A;&#x5E38;&#x7701;&#x7565;&#x5B83;&#x3002;</p>
<h2 id="&#x4E66;&#x5199;&#x5B8C;&#x6574;&#x51FD;&#x6570;&#x7C7B;&#x578B;">&#x4E66;&#x5199;&#x5B8C;&#x6574;&#x51FD;&#x6570;&#x7C7B;&#x578B;</h2>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x4E3A;&#x51FD;&#x6570;&#x6307;&#x5B9A;&#x4E86;&#x7C7B;&#x578B;&#xFF0C;&#x4E0B;&#x9762;&#x8BA9;&#x6211;&#x4EEC;&#x5199;&#x51FA;&#x51FD;&#x6570;&#x7684;&#x5B8C;&#x6574;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> myAdd: (x:<span class="hljs-built_in">number</span>, y:<span class="hljs-built_in">number</span>) =&gt; <span class="hljs-built_in">number</span> =
    <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">x: <span class="hljs-built_in">number</span>, y: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">number</span> </span>{ <span class="hljs-keyword">return</span> x + y; };
</code></pre>
<p>&#x51FD;&#x6570;&#x7C7B;&#x578B;&#x5305;&#x542B;&#x4E24;&#x90E8;&#x5206;&#xFF1A;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x3002;
&#x5F53;&#x5199;&#x51FA;&#x5B8C;&#x6574;&#x51FD;&#x6570;&#x7C7B;&#x578B;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8FD9;&#x4E24;&#x90E8;&#x5206;&#x90FD;&#x662F;&#x9700;&#x8981;&#x7684;&#x3002;
&#x6211;&#x4EEC;&#x4EE5;&#x53C2;&#x6570;&#x5217;&#x8868;&#x7684;&#x5F62;&#x5F0F;&#x5199;&#x51FA;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#xFF0C;&#x4E3A;&#x6BCF;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x540D;&#x5B57;&#x548C;&#x7C7B;&#x578B;&#x3002;
&#x8FD9;&#x4E2A;&#x540D;&#x5B57;&#x53EA;&#x662F;&#x4E3A;&#x4E86;&#x589E;&#x52A0;&#x53EF;&#x8BFB;&#x6027;&#x3002;
&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x8FD9;&#x4E48;&#x5199;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> myAdd: (baseValue: <span class="hljs-built_in">number</span>, increment: <span class="hljs-built_in">number</span>) =&gt; <span class="hljs-built_in">number</span> =
    <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">x: <span class="hljs-built_in">number</span>, y: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">number</span> </span>{ <span class="hljs-keyword">return</span> x + y; };
</code></pre>
<p>&#x53EA;&#x8981;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x662F;&#x5339;&#x914D;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x8BA4;&#x4E3A;&#x5B83;&#x662F;&#x6709;&#x6548;&#x7684;&#x51FD;&#x6570;&#x7C7B;&#x578B;&#xFF0C;&#x800C;&#x4E0D;&#x5728;&#x4E4E;&#x53C2;&#x6570;&#x540D;&#x662F;&#x5426;&#x6B63;&#x786E;&#x3002;</p>
<p>&#x7B2C;&#x4E8C;&#x90E8;&#x5206;&#x662F;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x3002;
&#x5BF9;&#x4E8E;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x6211;&#x4EEC;&#x5728;&#x51FD;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x4E4B;&#x524D;&#x4F7F;&#x7528;(<code>=&gt;</code>)&#x7B26;&#x53F7;&#xFF0C;&#x4F7F;&#x4E4B;&#x6E05;&#x6670;&#x660E;&#x4E86;&#x3002;
&#x5982;&#x4E4B;&#x524D;&#x63D0;&#x5230;&#x7684;&#xFF0C;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x662F;&#x51FD;&#x6570;&#x7C7B;&#x578B;&#x7684;&#x5FC5;&#x8981;&#x90E8;&#x5206;&#xFF0C;&#x5982;&#x679C;&#x51FD;&#x6570;&#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x4EFB;&#x4F55;&#x503C;&#xFF0C;&#x4F60;&#x4E5F;&#x5FC5;&#x987B;&#x6307;&#x5B9A;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x4E3A;<code>void</code>&#x800C;&#x4E0D;&#x80FD;&#x7559;&#x7A7A;&#x3002;</p>
<p>&#x51FD;&#x6570;&#x7684;&#x7C7B;&#x578B;&#x53EA;&#x662F;&#x7531;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x7EC4;&#x6210;&#x7684;&#x3002;
&#x51FD;&#x6570;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x6355;&#x83B7;&#x53D8;&#x91CF;&#x4E0D;&#x4F1A;&#x4F53;&#x73B0;&#x5728;&#x7C7B;&#x578B;&#x91CC;&#x3002;
&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x8FD9;&#x4E9B;&#x53D8;&#x91CF;&#x662F;&#x51FD;&#x6570;&#x7684;&#x9690;&#x85CF;&#x72B6;&#x6001;&#x5E76;&#x4E0D;&#x662F;&#x7EC4;&#x6210;API&#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;</p>
<h2 id="&#x63A8;&#x65AD;&#x7C7B;&#x578B;">&#x63A8;&#x65AD;&#x7C7B;&#x578B;</h2>
<p>&#x5C1D;&#x8BD5;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F60;&#x4F1A;&#x53D1;&#x73B0;&#x5982;&#x679C;&#x4F60;&#x5728;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x7684;&#x4E00;&#x8FB9;&#x6307;&#x5B9A;&#x4E86;&#x7C7B;&#x578B;&#x4F46;&#x662F;&#x53E6;&#x4E00;&#x8FB9;&#x6CA1;&#x6709;&#x7C7B;&#x578B;&#x7684;&#x8BDD;&#xFF0C;TypeScript&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x81EA;&#x52A8;&#x8BC6;&#x522B;&#x51FA;&#x7C7B;&#x578B;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-comment">// myAdd has the full function type</span>
<span class="hljs-keyword">let</span> myAdd = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">x: <span class="hljs-built_in">number</span>, y: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">number</span> </span>{ <span class="hljs-keyword">return</span> x + y; };

<span class="hljs-comment">// The parameters `x` and `y` have the type number</span>
<span class="hljs-keyword">let</span> myAdd: (baseValue: <span class="hljs-built_in">number</span>, increment: <span class="hljs-built_in">number</span>) =&gt; <span class="hljs-built_in">number</span> =
    <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">x, y</span>) </span>{ <span class="hljs-keyword">return</span> x + y; };
</code></pre>
<p>&#x8FD9;&#x53EB;&#x505A;&#x201C;&#x6309;&#x4E0A;&#x4E0B;&#x6587;&#x5F52;&#x7C7B;&#x201D;&#xFF0C;&#x662F;&#x7C7B;&#x578B;&#x63A8;&#x8BBA;&#x7684;&#x4E00;&#x79CD;&#x3002;
&#x5B83;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x66F4;&#x597D;&#x5730;&#x4E3A;&#x7A0B;&#x5E8F;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x3002;</p>
<h1 id="&#x53EF;&#x9009;&#x53C2;&#x6570;&#x548C;&#x9ED8;&#x8BA4;&#x53C2;&#x6570;">&#x53EF;&#x9009;&#x53C2;&#x6570;&#x548C;&#x9ED8;&#x8BA4;&#x53C2;&#x6570;</h1>
<p>TypeScript&#x91CC;&#x7684;&#x6BCF;&#x4E2A;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x90FD;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;
&#x8FD9;&#x4E0D;&#x662F;&#x6307;&#x4E0D;&#x80FD;&#x4F20;&#x9012;<code>null</code>&#x6216;<code>undefined</code>&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x800C;&#x662F;&#x8BF4;&#x7F16;&#x8BD1;&#x5668;&#x68C0;&#x67E5;&#x7528;&#x6237;&#x662F;&#x5426;&#x4E3A;&#x6BCF;&#x4E2A;&#x53C2;&#x6570;&#x90FD;&#x4F20;&#x5165;&#x4E86;&#x503C;&#x3002;
&#x7F16;&#x8BD1;&#x5668;&#x8FD8;&#x4F1A;&#x5047;&#x8BBE;&#x53EA;&#x6709;&#x8FD9;&#x4E9B;&#x53C2;&#x6570;&#x4F1A;&#x88AB;&#x4F20;&#x9012;&#x8FDB;&#x51FD;&#x6570;&#x3002;
&#x7B80;&#x77ED;&#x5730;&#x8BF4;&#xFF0C;&#x4F20;&#x9012;&#x7ED9;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x5FC5;&#x987B;&#x4E0E;&#x51FD;&#x6570;&#x671F;&#x671B;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x4E00;&#x81F4;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buildName</span>(<span class="hljs-params">firstName: <span class="hljs-built_in">string</span>, lastName: <span class="hljs-built_in">string</span></span>) </span>{
    <span class="hljs-keyword">return</span> firstName + <span class="hljs-string">&quot; &quot;</span> + lastName;
}

<span class="hljs-keyword">let</span> result1 = buildName(<span class="hljs-string">&quot;Bob&quot;</span>);                  <span class="hljs-comment">// error, too few parameters</span>
<span class="hljs-keyword">let</span> result2 = buildName(<span class="hljs-string">&quot;Bob&quot;</span>, <span class="hljs-string">&quot;Adams&quot;</span>, <span class="hljs-string">&quot;Sr.&quot;</span>);  <span class="hljs-comment">// error, too many parameters</span>
<span class="hljs-keyword">let</span> result3 = buildName(<span class="hljs-string">&quot;Bob&quot;</span>, <span class="hljs-string">&quot;Adams&quot;</span>);         <span class="hljs-comment">// ah, just right</span>
</code></pre>
<p>JavaScript&#x91CC;&#xFF0C;&#x6BCF;&#x4E2A;&#x53C2;&#x6570;&#x90FD;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x53EF;&#x4F20;&#x53EF;&#x4E0D;&#x4F20;&#x3002;
&#x6CA1;&#x4F20;&#x53C2;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5B83;&#x7684;&#x503C;&#x5C31;&#x662F;undefined&#x3002;
&#x5728;TypeScript&#x91CC;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x53C2;&#x6570;&#x540D;&#x65C1;&#x4F7F;&#x7528;<code>?</code>&#x5B9E;&#x73B0;&#x53EF;&#x9009;&#x53C2;&#x6570;&#x7684;&#x529F;&#x80FD;&#x3002;
&#x6BD4;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x60F3;&#x8BA9;last name&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buildName</span>(<span class="hljs-params">firstName: <span class="hljs-built_in">string</span>, lastName?: <span class="hljs-built_in">string</span></span>) </span>{
    <span class="hljs-keyword">if</span> (lastName)
        <span class="hljs-keyword">return</span> firstName + <span class="hljs-string">&quot; &quot;</span> + lastName;
    <span class="hljs-keyword">else</span>
        <span class="hljs-keyword">return</span> firstName;
}

<span class="hljs-keyword">let</span> result1 = buildName(<span class="hljs-string">&quot;Bob&quot;</span>);  <span class="hljs-comment">// works correctly now</span>
<span class="hljs-keyword">let</span> result2 = buildName(<span class="hljs-string">&quot;Bob&quot;</span>, <span class="hljs-string">&quot;Adams&quot;</span>, <span class="hljs-string">&quot;Sr.&quot;</span>);  <span class="hljs-comment">// error, too many parameters</span>
<span class="hljs-keyword">let</span> result3 = buildName(<span class="hljs-string">&quot;Bob&quot;</span>, <span class="hljs-string">&quot;Adams&quot;</span>);  <span class="hljs-comment">// ah, just right</span>
</code></pre>
<p>&#x53EF;&#x9009;&#x53C2;&#x6570;&#x5FC5;&#x987B;&#x8DDF;&#x5728;&#x5FC5;&#x987B;&#x53C2;&#x6570;&#x540E;&#x9762;&#x3002;
&#x5982;&#x679C;&#x4E0A;&#x4F8B;&#x6211;&#x4EEC;&#x60F3;&#x8BA9;first name&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x5FC5;&#x987B;&#x8C03;&#x6574;&#x5B83;&#x4EEC;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x628A;first name&#x653E;&#x5728;&#x540E;&#x9762;&#x3002;</p>
<p>&#x5728;TypeScript&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x4E3A;&#x53C2;&#x6570;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x503C;&#x5F53;&#x7528;&#x6237;&#x6CA1;&#x6709;&#x4F20;&#x9012;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x6216;&#x4F20;&#x9012;&#x7684;&#x503C;&#x662F;<code>undefined</code>&#x65F6;&#x3002;
&#x5B83;&#x4EEC;&#x53EB;&#x505A;&#x6709;&#x9ED8;&#x8BA4;&#x521D;&#x59CB;&#x5316;&#x503C;&#x7684;&#x53C2;&#x6570;&#x3002;
&#x8BA9;&#x6211;&#x4EEC;&#x4FEE;&#x6539;&#x4E0A;&#x4F8B;&#xFF0C;&#x628A;last name&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x8BBE;&#x7F6E;&#x4E3A;<code>&quot;Smith&quot;</code>&#x3002;</p>
<pre><code class="lang-ts">function buildName(firstName: string, lastName = &quot;Smith&quot;) {
    return firstName + &quot; &quot; + lastName;
}

let result1 = buildName(&quot;Bob&quot;);                  // works correctly now, returns &quot;Bob Smith&quot;
let result2 = buildName(&quot;Bob&quot;, undefined);       // still works, also returns &quot;Bob Smith&quot;
let result3 = buildName(&quot;Bob&quot;, &quot;Adams&quot;, &quot;Sr.&quot;);  // error, too many parameters
let result4 = buildName(&quot;Bob&quot;, &quot;Adams&quot;);         // ah, just right
</code></pre>
<p>&#x5728;&#x6240;&#x6709;&#x5FC5;&#x987B;&#x53C2;&#x6570;&#x540E;&#x9762;&#x7684;&#x5E26;&#x9ED8;&#x8BA4;&#x521D;&#x59CB;&#x5316;&#x7684;&#x53C2;&#x6570;&#x90FD;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x4E0E;&#x53EF;&#x9009;&#x53C2;&#x6570;&#x4E00;&#x6837;&#xFF0C;&#x5728;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x7684;&#x65F6;&#x5019;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#x3002;
&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x53EF;&#x9009;&#x53C2;&#x6570;&#x4E0E;&#x672B;&#x5C3E;&#x7684;&#x9ED8;&#x8BA4;&#x53C2;&#x6570;&#x5171;&#x4EAB;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buildName</span>(<span class="hljs-params">firstName: <span class="hljs-built_in">string</span>, lastName?: <span class="hljs-built_in">string</span></span>) </span>{
    <span class="hljs-comment">// ...</span>
}
</code></pre>
<p>&#x548C;</p>
<pre><code class="lang-ts">function buildName(firstName: string, lastName = &quot;Smith&quot;) {
    // ...
}
</code></pre>
<p>&#x5171;&#x4EAB;&#x540C;&#x6837;&#x7684;&#x7C7B;&#x578B;<code>(firstName: string, lastName?: string) =&gt; string</code>&#x3002;
&#x9ED8;&#x8BA4;&#x53C2;&#x6570;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x6D88;&#x5931;&#x4E86;&#xFF0C;&#x53EA;&#x4FDD;&#x7559;&#x4E86;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x53EF;&#x9009;&#x53C2;&#x6570;&#x7684;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x4E0E;&#x666E;&#x901A;&#x53EF;&#x9009;&#x53C2;&#x6570;&#x4E0D;&#x540C;&#x7684;&#x662F;&#xFF0C;&#x5E26;&#x9ED8;&#x8BA4;&#x503C;&#x7684;&#x53C2;&#x6570;&#x4E0D;&#x9700;&#x8981;&#x653E;&#x5728;&#x5FC5;&#x987B;&#x53C2;&#x6570;&#x7684;&#x540E;&#x9762;&#x3002;
&#x5982;&#x679C;&#x5E26;&#x9ED8;&#x8BA4;&#x503C;&#x7684;&#x53C2;&#x6570;&#x51FA;&#x73B0;&#x5728;&#x5FC5;&#x987B;&#x53C2;&#x6570;&#x524D;&#x9762;&#xFF0C;&#x7528;&#x6237;&#x5FC5;&#x987B;&#x660E;&#x786E;&#x7684;&#x4F20;&#x5165;<code>undefined</code>&#x503C;&#x6765;&#x83B7;&#x5F97;&#x9ED8;&#x8BA4;&#x503C;&#x3002;
&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x91CD;&#x5199;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x8BA9;<code>firstName</code>&#x662F;&#x5E26;&#x9ED8;&#x8BA4;&#x503C;&#x7684;&#x53C2;&#x6570;&#xFF1A;</p>
<pre><code class="lang-ts">function buildName(firstName = &quot;Will&quot;, lastName: string) {
    return firstName + &quot; &quot; + lastName;
}

let result1 = buildName(&quot;Bob&quot;);                  // error, too few parameters
let result2 = buildName(&quot;Bob&quot;, &quot;Adams&quot;, &quot;Sr.&quot;);  // error, too many parameters
let result3 = buildName(&quot;Bob&quot;, &quot;Adams&quot;);         // okay and returns &quot;Bob Adams&quot;
let result4 = buildName(undefined, &quot;Adams&quot;);     // okay and returns &quot;Will Adams&quot;
</code></pre>
<h1 id="&#x5269;&#x4F59;&#x53C2;&#x6570;">&#x5269;&#x4F59;&#x53C2;&#x6570;</h1>
<p>&#x5FC5;&#x8981;&#x53C2;&#x6570;&#xFF0C;&#x9ED8;&#x8BA4;&#x53C2;&#x6570;&#x548C;&#x53EF;&#x9009;&#x53C2;&#x6570;&#x6709;&#x4E2A;&#x5171;&#x540C;&#x70B9;&#xFF1A;&#x5B83;&#x4EEC;&#x8868;&#x793A;&#x67D0;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x3002;
&#x6709;&#x65F6;&#xFF0C;&#x4F60;&#x60F3;&#x540C;&#x65F6;&#x64CD;&#x4F5C;&#x591A;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x6216;&#x8005;&#x4F60;&#x5E76;&#x4E0D;&#x77E5;&#x9053;&#x4F1A;&#x6709;&#x591A;&#x5C11;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x8FDB;&#x6765;&#x3002;
&#x5728;JavaScript&#x91CC;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>arguments</code>&#x6765;&#x8BBF;&#x95EE;&#x6240;&#x6709;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<p>&#x5728;TypeScript&#x91CC;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x628A;&#x6240;&#x6709;&#x53C2;&#x6570;&#x6536;&#x96C6;&#x5230;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x91CC;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buildName</span>(<span class="hljs-params">firstName: <span class="hljs-built_in">string</span>, ...restOfName: <span class="hljs-built_in">string</span>[]</span>) </span>{
  <span class="hljs-keyword">return</span> firstName + <span class="hljs-string">&quot; &quot;</span> + restOfName.join(<span class="hljs-string">&quot; &quot;</span>);
}

<span class="hljs-keyword">let</span> employeeName = buildName(<span class="hljs-string">&quot;Joseph&quot;</span>, <span class="hljs-string">&quot;Samuel&quot;</span>, <span class="hljs-string">&quot;Lucas&quot;</span>, <span class="hljs-string">&quot;MacKinzie&quot;</span>);
</code></pre>
<p>&#x5269;&#x4F59;&#x53C2;&#x6570;&#x4F1A;&#x88AB;&#x5F53;&#x505A;&#x4E2A;&#x6570;&#x4E0D;&#x9650;&#x7684;&#x53EF;&#x9009;&#x53C2;&#x6570;&#x3002;
&#x53EF;&#x4EE5;&#x4E00;&#x4E2A;&#x90FD;&#x6CA1;&#x6709;&#xFF0C;&#x540C;&#x6837;&#x4E5F;&#x53EF;&#x4EE5;&#x6709;&#x4EFB;&#x610F;&#x4E2A;&#x3002;
&#x7F16;&#x8BD1;&#x5668;&#x521B;&#x5EFA;&#x53C2;&#x6570;&#x6570;&#x7EC4;&#xFF0C;&#x540D;&#x5B57;&#x662F;&#x4F60;&#x5728;&#x7701;&#x7565;&#x53F7;&#xFF08;<code>...</code>&#xFF09;&#x540E;&#x9762;&#x7ED9;&#x5B9A;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x6570;&#x7EC4;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x7701;&#x7565;&#x53F7;&#x4E5F;&#x4F1A;&#x5728;&#x5E26;&#x6709;&#x5269;&#x4F59;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x4E0A;&#x4F7F;&#x7528;&#x5230;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buildName</span>(<span class="hljs-params">firstName: <span class="hljs-built_in">string</span>, ...restOfName: <span class="hljs-built_in">string</span>[]</span>) </span>{
  <span class="hljs-keyword">return</span> firstName + <span class="hljs-string">&quot; &quot;</span> + restOfName.join(<span class="hljs-string">&quot; &quot;</span>);
}

<span class="hljs-keyword">let</span> buildNameFun: (fname: <span class="hljs-built_in">string</span>, ...rest: <span class="hljs-built_in">string</span>[]) =&gt; <span class="hljs-built_in">string</span> = buildName;
</code></pre>
<h1 id="this"><code>this</code></h1>
<p>&#x5B66;&#x4E60;&#x5982;&#x4F55;&#x5728;JavaScript&#x91CC;&#x6B63;&#x786E;&#x4F7F;&#x7528;<code>this</code>&#x5C31;&#x597D;&#x6BD4;&#x4E00;&#x573A;&#x6210;&#x5E74;&#x793C;&#x3002;
&#x7531;&#x4E8E;TypeScript&#x662F;JavaScript&#x7684;&#x8D85;&#x96C6;&#xFF0C;TypeScript&#x7A0B;&#x5E8F;&#x5458;&#x4E5F;&#x9700;&#x8981;&#x5F04;&#x6E05;<code>this</code>&#x5DE5;&#x4F5C;&#x673A;&#x5236;&#x5E76;&#x4E14;&#x5F53;&#x6709;bug&#x7684;&#x65F6;&#x5019;&#x80FD;&#x591F;&#x627E;&#x51FA;&#x9519;&#x8BEF;&#x6240;&#x5728;&#x3002;
&#x5E78;&#x8FD0;&#x7684;&#x662F;&#xFF0C;TypeScript&#x80FD;&#x901A;&#x77E5;&#x4F60;&#x9519;&#x8BEF;&#x5730;&#x4F7F;&#x7528;&#x4E86;<code>this</code>&#x7684;&#x5730;&#x65B9;&#x3002;
&#x5982;&#x679C;&#x4F60;&#x60F3;&#x4E86;&#x89E3;JavaScript&#x91CC;&#x7684;<code>this</code>&#x662F;&#x5982;&#x4F55;&#x5DE5;&#x4F5C;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x9996;&#x5148;&#x9605;&#x8BFB;Yehuda Katz&#x5199;&#x7684;<a href="http://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/" target="_blank">Understanding JavaScript Function Invocation and &quot;this&quot;</a>&#x3002;
Yehuda&#x7684;&#x6587;&#x7AE0;&#x8BE6;&#x7EC6;&#x7684;&#x9610;&#x8FF0;&#x4E86;<code>this</code>&#x7684;&#x5185;&#x90E8;&#x5DE5;&#x4F5C;&#x539F;&#x7406;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x8FD9;&#x91CC;&#x53EA;&#x505A;&#x7B80;&#x5355;&#x4ECB;&#x7ECD;&#x3002;</p>
<h2 id="this&#x548C;&#x7BAD;&#x5934;&#x51FD;&#x6570;"><code>this</code>&#x548C;&#x7BAD;&#x5934;&#x51FD;&#x6570;</h2>
<p>JavaScript&#x91CC;&#xFF0C;<code>this</code>&#x7684;&#x503C;&#x5728;&#x51FD;&#x6570;&#x88AB;&#x8C03;&#x7528;&#x7684;&#x65F6;&#x5019;&#x624D;&#x4F1A;&#x6307;&#x5B9A;&#x3002;
&#x8FD9;&#x662F;&#x4E2A;&#x65E2;&#x5F3A;&#x5927;&#x53C8;&#x7075;&#x6D3B;&#x7684;&#x7279;&#x70B9;&#xFF0C;&#x4F46;&#x662F;&#x4F60;&#x9700;&#x8981;&#x82B1;&#x70B9;&#x65F6;&#x95F4;&#x5F04;&#x6E05;&#x695A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7684;&#x4E0A;&#x4E0B;&#x6587;&#x662F;&#x4EC0;&#x4E48;&#x3002;
&#x4F46;&#x4F17;&#x6240;&#x5468;&#x77E5;&#xFF0C;&#x8FD9;&#x4E0D;&#x662F;&#x4E00;&#x4EF6;&#x5F88;&#x7B80;&#x5355;&#x7684;&#x4E8B;&#xFF0C;&#x5C24;&#x5176;&#x662F;&#x5728;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x6216;&#x5C06;&#x51FD;&#x6570;&#x5F53;&#x505A;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x7684;&#x65F6;&#x5019;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x770B;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> deck = {
    suits: [<span class="hljs-string">&quot;hearts&quot;</span>, <span class="hljs-string">&quot;spades&quot;</span>, <span class="hljs-string">&quot;clubs&quot;</span>, <span class="hljs-string">&quot;diamonds&quot;</span>],
    cards: <span class="hljs-built_in">Array</span>(<span class="hljs-number">52</span>),
    createCardPicker: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
            <span class="hljs-keyword">let</span> pickedCard = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * <span class="hljs-number">52</span>);
            <span class="hljs-keyword">let</span> pickedSuit = <span class="hljs-built_in">Math</span>.floor(pickedCard / <span class="hljs-number">13</span>);

            <span class="hljs-keyword">return</span> {suit: <span class="hljs-keyword">this</span>.suits[pickedSuit], card: pickedCard % <span class="hljs-number">13</span>};
        }
    }
}

<span class="hljs-keyword">let</span> cardPicker = deck.createCardPicker();
<span class="hljs-keyword">let</span> pickedCard = cardPicker();

alert(<span class="hljs-string">&quot;card: &quot;</span> + pickedCard.card + <span class="hljs-string">&quot; of &quot;</span> + pickedCard.suit);
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;<code>createCardPicker</code>&#x662F;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x5E76;&#x4E14;&#x5B83;&#x53C8;&#x8FD4;&#x56DE;&#x4E86;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x3002;
&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5C1D;&#x8BD5;&#x8FD0;&#x884C;&#x8FD9;&#x4E2A;&#x7A0B;&#x5E8F;&#xFF0C;&#x4F1A;&#x53D1;&#x73B0;&#x5B83;&#x5E76;&#x6CA1;&#x6709;&#x5F39;&#x51FA;&#x5BF9;&#x8BDD;&#x6846;&#x800C;&#x662F;&#x62A5;&#x9519;&#x4E86;&#x3002;
&#x56E0;&#x4E3A;<code>createCardPicker</code>&#x8FD4;&#x56DE;&#x7684;&#x51FD;&#x6570;&#x91CC;&#x7684;<code>this</code>&#x88AB;&#x8BBE;&#x7F6E;&#x6210;&#x4E86;<code>window</code>&#x800C;&#x4E0D;&#x662F;<code>deck</code>&#x5BF9;&#x8C61;&#x3002;
&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x53EA;&#x662F;&#x72EC;&#x7ACB;&#x7684;&#x8C03;&#x7528;&#x4E86;<code>cardPicker()</code>&#x3002;
&#x9876;&#x7EA7;&#x7684;&#x975E;&#x65B9;&#x6CD5;&#x5F0F;&#x8C03;&#x7528;&#x4F1A;&#x5C06;<code>this</code>&#x89C6;&#x4E3A;<code>window</code>&#x3002;
&#xFF08;&#x6CE8;&#x610F;&#xFF1A;&#x5728;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;<code>this</code>&#x4E3A;<code>undefined</code>&#x800C;&#x4E0D;&#x662F;<code>window</code>&#xFF09;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x51FD;&#x6570;&#x88AB;&#x8FD4;&#x56DE;&#x65F6;&#x5C31;&#x7ED1;&#x597D;&#x6B63;&#x786E;&#x7684;<code>this</code>&#x3002;
&#x8FD9;&#x6837;&#x7684;&#x8BDD;&#xFF0C;&#x65E0;&#x8BBA;&#x4E4B;&#x540E;&#x600E;&#x4E48;&#x4F7F;&#x7528;&#x5B83;&#xFF0C;&#x90FD;&#x4F1A;&#x5F15;&#x7528;&#x7ED1;&#x5B9A;&#x7684;&#x2018;deck&#x2019;&#x5BF9;&#x8C61;&#x3002;
&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6539;&#x53D8;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x6765;&#x4F7F;&#x7528;ECMAScript 6&#x7BAD;&#x5934;&#x8BED;&#x6CD5;&#x3002;
&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x80FD;&#x4FDD;&#x5B58;&#x51FD;&#x6570;&#x521B;&#x5EFA;&#x65F6;&#x7684;<code>this</code>&#x503C;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x8C03;&#x7528;&#x65F6;&#x7684;&#x503C;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> deck = {
    suits: [<span class="hljs-string">&quot;hearts&quot;</span>, <span class="hljs-string">&quot;spades&quot;</span>, <span class="hljs-string">&quot;clubs&quot;</span>, <span class="hljs-string">&quot;diamonds&quot;</span>],
    cards: <span class="hljs-built_in">Array</span>(<span class="hljs-number">52</span>),
    createCardPicker: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-comment">// <span class="hljs-doctag">NOTE:</span> the line below is now an arrow function, allowing us to capture &apos;this&apos; right here</span>
        <span class="hljs-keyword">return</span> () =&gt; {
            <span class="hljs-keyword">let</span> pickedCard = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * <span class="hljs-number">52</span>);
            <span class="hljs-keyword">let</span> pickedSuit = <span class="hljs-built_in">Math</span>.floor(pickedCard / <span class="hljs-number">13</span>);

            <span class="hljs-keyword">return</span> {suit: <span class="hljs-keyword">this</span>.suits[pickedSuit], card: pickedCard % <span class="hljs-number">13</span>};
        }
    }
}

<span class="hljs-keyword">let</span> cardPicker = deck.createCardPicker();
<span class="hljs-keyword">let</span> pickedCard = cardPicker();

alert(<span class="hljs-string">&quot;card: &quot;</span> + pickedCard.card + <span class="hljs-string">&quot; of &quot;</span> + pickedCard.suit);
</code></pre>
<p>&#x66F4;&#x597D;&#x4E8B;&#x60C5;&#x662F;&#xFF0C;TypeScript&#x4F1A;&#x8B66;&#x544A;&#x4F60;&#x72AF;&#x4E86;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x7ED9;&#x7F16;&#x8BD1;&#x5668;&#x8BBE;&#x7F6E;&#x4E86;<code>--noImplicitThis</code>&#x6807;&#x8BB0;&#x3002;
&#x5B83;&#x4F1A;&#x6307;&#x51FA;<code>this.suits[pickedSuit]</code>&#x91CC;&#x7684;<code>this</code>&#x7684;&#x7C7B;&#x578B;&#x4E3A;<code>any</code>&#x3002;</p>
<h2 id="this&#x53C2;&#x6570;"><code>this</code>&#x53C2;&#x6570;</h2>
<p>&#x4E0D;&#x5E78;&#x7684;&#x662F;&#xFF0C;<code>this.suits[pickedSuit]</code>&#x7684;&#x7C7B;&#x578B;&#x4F9D;&#x65E7;&#x4E3A;<code>any</code>&#x3002;
&#x8FD9;&#x662F;&#x56E0;&#x4E3A;<code>this</code>&#x6765;&#x81EA;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x91CC;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x3002;
&#x4FEE;&#x6539;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#xFF0C;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x663E;&#x5F0F;&#x7684;<code>this</code>&#x53C2;&#x6570;&#x3002;
<code>this</code>&#x53C2;&#x6570;&#x662F;&#x4E2A;&#x5047;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5B83;&#x51FA;&#x73B0;&#x5728;&#x53C2;&#x6570;&#x5217;&#x8868;&#x7684;&#x6700;&#x524D;&#x9762;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"><span class="hljs-keyword">this</span>: <span class="hljs-built_in">void</span></span>) </span>{
    <span class="hljs-comment">// make sure `this` is unusable in this standalone function</span>
}
</code></pre>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x5F80;&#x4F8B;&#x5B50;&#x91CC;&#x6DFB;&#x52A0;&#x4E00;&#x4E9B;&#x63A5;&#x53E3;&#xFF0C;<code>Card</code> &#x548C; <code>Deck</code>&#xFF0C;&#x8BA9;&#x7C7B;&#x578B;&#x91CD;&#x7528;&#x80FD;&#x591F;&#x53D8;&#x5F97;&#x6E05;&#x6670;&#x7B80;&#x5355;&#x4E9B;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> Card {
    suit: <span class="hljs-built_in">string</span>;
    card: <span class="hljs-built_in">number</span>;
}
<span class="hljs-keyword">interface</span> Deck {
    suits: <span class="hljs-built_in">string</span>[];
    cards: <span class="hljs-built_in">number</span>[];
    createCardPicker(<span class="hljs-keyword">this</span>: Deck): () =&gt; Card;
}
<span class="hljs-keyword">let</span> deck: Deck = {
    suits: [<span class="hljs-string">&quot;hearts&quot;</span>, <span class="hljs-string">&quot;spades&quot;</span>, <span class="hljs-string">&quot;clubs&quot;</span>, <span class="hljs-string">&quot;diamonds&quot;</span>],
    cards: <span class="hljs-built_in">Array</span>(<span class="hljs-number">52</span>),
    <span class="hljs-comment">// <span class="hljs-doctag">NOTE:</span> The function now explicitly specifies that its callee must be of type Deck</span>
    createCardPicker: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"><span class="hljs-keyword">this</span>: Deck</span>) </span>{
        <span class="hljs-keyword">return</span> () =&gt; {
            <span class="hljs-keyword">let</span> pickedCard = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * <span class="hljs-number">52</span>);
            <span class="hljs-keyword">let</span> pickedSuit = <span class="hljs-built_in">Math</span>.floor(pickedCard / <span class="hljs-number">13</span>);

            <span class="hljs-keyword">return</span> {suit: <span class="hljs-keyword">this</span>.suits[pickedSuit], card: pickedCard % <span class="hljs-number">13</span>};
        }
    }
}

<span class="hljs-keyword">let</span> cardPicker = deck.createCardPicker();
<span class="hljs-keyword">let</span> pickedCard = cardPicker();

alert(<span class="hljs-string">&quot;card: &quot;</span> + pickedCard.card + <span class="hljs-string">&quot; of &quot;</span> + pickedCard.suit);
</code></pre>
<p>&#x73B0;&#x5728;TypeScript&#x77E5;&#x9053;<code>createCardPicker</code>&#x671F;&#x671B;&#x5728;&#x67D0;&#x4E2A;<code>Deck</code>&#x5BF9;&#x8C61;&#x4E0A;&#x8C03;&#x7528;&#x3002;
&#x4E5F;&#x5C31;&#x662F;&#x8BF4;<code>this</code>&#x662F;<code>Deck</code>&#x7C7B;&#x578B;&#x7684;&#xFF0C;&#x800C;&#x975E;<code>any</code>&#xFF0C;&#x56E0;&#x6B64;<code>--noImplicitThis</code>&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#x4E86;&#x3002;</p>
<h3 id="&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x91CC;&#x7684;this&#x53C2;&#x6570;">&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x91CC;&#x7684;<code>this</code>&#x53C2;&#x6570;</h3>
<p>&#x5F53;&#x4F60;&#x5C06;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x4F20;&#x9012;&#x5230;&#x67D0;&#x4E2A;&#x5E93;&#x51FD;&#x6570;&#x91CC;&#x5728;&#x7A0D;&#x540E;&#x88AB;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x4F60;&#x53EF;&#x80FD;&#x4E5F;&#x89C1;&#x5230;&#x8FC7;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x91CC;&#x7684;<code>this</code>&#x4F1A;&#x62A5;&#x9519;&#x3002;
&#x56E0;&#x4E3A;&#x5F53;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x88AB;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x5B83;&#x4F1A;&#x88AB;&#x5F53;&#x6210;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#xFF0C;<code>this</code>&#x5C06;&#x4E3A;<code>undefined</code>&#x3002;
&#x7A0D;&#x505A;&#x6539;&#x52A8;&#xFF0C;&#x4F60;&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>this</code>&#x53C2;&#x6570;&#x6765;&#x907F;&#x514D;&#x9519;&#x8BEF;&#x3002;
&#x9996;&#x5148;&#xFF0C;&#x5E93;&#x51FD;&#x6570;&#x7684;&#x4F5C;&#x8005;&#x8981;&#x6307;&#x5B9A;<code>this</code>&#x7684;&#x7C7B;&#x578B;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> UIElement {
    addClickListener(onclick: (<span class="hljs-keyword">this</span>: <span class="hljs-built_in">void</span>, e: Event) =&gt; <span class="hljs-built_in">void</span>): <span class="hljs-built_in">void</span>;
}
</code></pre>
<p><code>this: void</code>&#x610F;&#x5473;&#x7740;<code>addClickListener</code>&#x671F;&#x671B;<code>onclick</code>&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x4E14;&#x5B83;&#x4E0D;&#x9700;&#x8981;&#x4E00;&#x4E2A;<code>this</code>&#x7C7B;&#x578B;&#x3002;
&#x7136;&#x540E;&#xFF0C;&#x4E3A;&#x8C03;&#x7528;&#x4EE3;&#x7801;&#x91CC;&#x7684;<code>this</code>&#x6DFB;&#x52A0;&#x7C7B;&#x578B;&#x6CE8;&#x89E3;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">class</span> Handler {
    info: <span class="hljs-built_in">string</span>;
    onClickBad(<span class="hljs-keyword">this</span>: Handler, e: Event) {
        <span class="hljs-comment">// oops, used this here. using this callback would crash at runtime</span>
        <span class="hljs-keyword">this</span>.info = e.message;
    }
}
<span class="hljs-keyword">let</span> h = <span class="hljs-keyword">new</span> Handler();
uiElement.addClickListener(h.onClickBad); <span class="hljs-comment">// error!</span>
</code></pre>
<p>&#x6307;&#x5B9A;&#x4E86;<code>this</code>&#x7C7B;&#x578B;&#x540E;&#xFF0C;&#x4F60;&#x663E;&#x5F0F;&#x58F0;&#x660E;<code>onClickBad</code>&#x5FC5;&#x987B;&#x5728;<code>Handler</code>&#x7684;&#x5B9E;&#x4F8B;&#x4E0A;&#x8C03;&#x7528;&#x3002;
&#x7136;&#x540E;TypeScript&#x4F1A;&#x68C0;&#x6D4B;&#x5230;<code>addClickListener</code>&#x8981;&#x6C42;&#x51FD;&#x6570;&#x5E26;&#x6709;<code>this: void</code>&#x3002;
&#x6539;&#x53D8;<code>this</code>&#x7C7B;&#x578B;&#x6765;&#x4FEE;&#x590D;&#x8FD9;&#x4E2A;&#x9519;&#x8BEF;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">class</span> Handler {
    info: <span class="hljs-built_in">string</span>;
    onClickGood(<span class="hljs-keyword">this</span>: <span class="hljs-built_in">void</span>, e: Event) {
        <span class="hljs-comment">// can&apos;t use this here because it&apos;s of type void!</span>
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;clicked!&apos;</span>);
    }
}
<span class="hljs-keyword">let</span> h = <span class="hljs-keyword">new</span> Handler();
uiElement.addClickListener(h.onClickGood);
</code></pre>
<p>&#x56E0;&#x4E3A;<code>onClickGood</code>&#x6307;&#x5B9A;&#x4E86;<code>this</code>&#x7C7B;&#x578B;&#x4E3A;<code>void</code>&#xFF0C;&#x56E0;&#x6B64;&#x4F20;&#x9012;<code>addClickListener</code>&#x662F;&#x5408;&#x6CD5;&#x7684;&#x3002;
&#x5F53;&#x7136;&#x4E86;&#xFF0C;&#x8FD9;&#x4E5F;&#x610F;&#x5473;&#x7740;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;<code>this.info</code>.
&#x5982;&#x679C;&#x4F60;&#x4E24;&#x8005;&#x90FD;&#x60F3;&#x8981;&#xFF0C;&#x4F60;&#x4E0D;&#x5F97;&#x4E0D;&#x4F7F;&#x7528;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E86;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">class</span> Handler {
    info: <span class="hljs-built_in">string</span>;
    onClickGood = (e: Event) =&gt; { <span class="hljs-keyword">this</span>.info = e.message }
}
</code></pre>
<p>&#x8FD9;&#x662F;&#x53EF;&#x884C;&#x7684;&#x56E0;&#x4E3A;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x4E0D;&#x4F1A;&#x6355;&#x83B7;<code>this</code>&#xFF0C;&#x6240;&#x4EE5;&#x4F60;&#x603B;&#x662F;&#x53EF;&#x4EE5;&#x628A;&#x5B83;&#x4EEC;&#x4F20;&#x7ED9;&#x671F;&#x671B;<code>this: void</code>&#x7684;&#x51FD;&#x6570;&#x3002;
&#x7F3A;&#x70B9;&#x662F;&#x6BCF;&#x4E2A;<code>Handler</code>&#x5BF9;&#x8C61;&#x90FD;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x3002;
&#x53E6;&#x4E00;&#x65B9;&#x9762;&#xFF0C;&#x65B9;&#x6CD5;&#x53EA;&#x4F1A;&#x88AB;&#x521B;&#x5EFA;&#x4E00;&#x6B21;&#xFF0C;&#x6DFB;&#x52A0;&#x5230;<code>Handler</code>&#x7684;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#x3002;
&#x5B83;&#x4EEC;&#x5728;&#x4E0D;&#x540C;<code>Handler</code>&#x5BF9;&#x8C61;&#x95F4;&#x662F;&#x5171;&#x4EAB;&#x7684;&#x3002;</p>
<h1 id="&#x91CD;&#x8F7D;">&#x91CD;&#x8F7D;</h1>
<p>JavaScript&#x672C;&#x8EAB;&#x662F;&#x4E2A;&#x52A8;&#x6001;&#x8BED;&#x8A00;&#x3002;
JavaScript&#x91CC;&#x51FD;&#x6570;&#x6839;&#x636E;&#x4F20;&#x5165;&#x4E0D;&#x540C;&#x7684;&#x53C2;&#x6570;&#x800C;&#x8FD4;&#x56DE;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x662F;&#x5F88;&#x5E38;&#x89C1;&#x7684;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> suits = [<span class="hljs-string">&quot;hearts&quot;</span>, <span class="hljs-string">&quot;spades&quot;</span>, <span class="hljs-string">&quot;clubs&quot;</span>, <span class="hljs-string">&quot;diamonds&quot;</span>];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">pickCard</span>(<span class="hljs-params">x</span>): <span class="hljs-title">any</span> </span>{
    <span class="hljs-comment">// Check to see if we&apos;re working with an object/array</span>
    <span class="hljs-comment">// if so, they gave us the deck and we&apos;ll pick the card</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> x == <span class="hljs-string">&quot;object&quot;</span>) {
        <span class="hljs-keyword">let</span> pickedCard = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * x.length);
        <span class="hljs-keyword">return</span> pickedCard;
    }
    <span class="hljs-comment">// Otherwise just let them pick the card</span>
    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> x == <span class="hljs-string">&quot;number&quot;</span>) {
        <span class="hljs-keyword">let</span> pickedSuit = <span class="hljs-built_in">Math</span>.floor(x / <span class="hljs-number">13</span>);
        <span class="hljs-keyword">return</span> { suit: suits[pickedSuit], card: x % <span class="hljs-number">13</span> };
    }
}

<span class="hljs-keyword">let</span> myDeck = [{ suit: <span class="hljs-string">&quot;diamonds&quot;</span>, card: <span class="hljs-number">2</span> }, { suit: <span class="hljs-string">&quot;spades&quot;</span>, card: <span class="hljs-number">10</span> }, { suit: <span class="hljs-string">&quot;hearts&quot;</span>, card: <span class="hljs-number">4</span> }];
<span class="hljs-keyword">let</span> pickedCard1 = myDeck[pickCard(myDeck)];
alert(<span class="hljs-string">&quot;card: &quot;</span> + pickedCard1.card + <span class="hljs-string">&quot; of &quot;</span> + pickedCard1.suit);

<span class="hljs-keyword">let</span> pickedCard2 = pickCard(<span class="hljs-number">15</span>);
alert(<span class="hljs-string">&quot;card: &quot;</span> + pickedCard2.card + <span class="hljs-string">&quot; of &quot;</span> + pickedCard2.suit);
</code></pre>
<p><code>pickCard</code>&#x65B9;&#x6CD5;&#x6839;&#x636E;&#x4F20;&#x5165;&#x53C2;&#x6570;&#x7684;&#x4E0D;&#x540C;&#x4F1A;&#x8FD4;&#x56DE;&#x4E24;&#x79CD;&#x4E0D;&#x540C;&#x7684;&#x7C7B;&#x578B;&#x3002;
&#x5982;&#x679C;&#x4F20;&#x5165;&#x7684;&#x662F;&#x4EE3;&#x8868;&#x7EB8;&#x724C;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x662F;&#x4ECE;&#x4E2D;&#x6293;&#x4E00;&#x5F20;&#x724C;&#x3002;
&#x5982;&#x679C;&#x7528;&#x6237;&#x60F3;&#x6293;&#x724C;&#xFF0C;&#x6211;&#x4EEC;&#x544A;&#x8BC9;&#x4ED6;&#x6293;&#x5230;&#x4E86;&#x4EC0;&#x4E48;&#x724C;&#x3002;
&#x4F46;&#x662F;&#x8FD9;&#x600E;&#x4E48;&#x5728;&#x7C7B;&#x578B;&#x7CFB;&#x7EDF;&#x91CC;&#x8868;&#x793A;&#x5462;&#x3002;</p>
<p>&#x65B9;&#x6CD5;&#x662F;&#x4E3A;&#x540C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x63D0;&#x4F9B;&#x591A;&#x4E2A;&#x51FD;&#x6570;&#x7C7B;&#x578B;&#x5B9A;&#x4E49;&#x6765;&#x8FDB;&#x884C;&#x51FD;&#x6570;&#x91CD;&#x8F7D;&#x3002;
&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x6839;&#x636E;&#x8FD9;&#x4E2A;&#x5217;&#x8868;&#x53BB;&#x5904;&#x7406;&#x51FD;&#x6570;&#x7684;&#x8C03;&#x7528;&#x3002;
&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x6765;&#x91CD;&#x8F7D;<code>pickCard</code>&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> suits = [<span class="hljs-string">&quot;hearts&quot;</span>, <span class="hljs-string">&quot;spades&quot;</span>, <span class="hljs-string">&quot;clubs&quot;</span>, <span class="hljs-string">&quot;diamonds&quot;</span>];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">pickCard</span>(<span class="hljs-params">x: {suit: <span class="hljs-built_in">string</span>; card: <span class="hljs-built_in">number</span>; }[]</span>): <span class="hljs-title">number</span></span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">pickCard</span>(<span class="hljs-params">x: <span class="hljs-built_in">number</span></span>): </span>{suit: <span class="hljs-built_in">string</span>; card: <span class="hljs-built_in">number</span>; };
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">pickCard</span>(<span class="hljs-params">x</span>): <span class="hljs-title">any</span> </span>{
    <span class="hljs-comment">// Check to see if we&apos;re working with an object/array</span>
    <span class="hljs-comment">// if so, they gave us the deck and we&apos;ll pick the card</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> x == <span class="hljs-string">&quot;object&quot;</span>) {
        <span class="hljs-keyword">let</span> pickedCard = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * x.length);
        <span class="hljs-keyword">return</span> pickedCard;
    }
    <span class="hljs-comment">// Otherwise just let them pick the card</span>
    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> x == <span class="hljs-string">&quot;number&quot;</span>) {
        <span class="hljs-keyword">let</span> pickedSuit = <span class="hljs-built_in">Math</span>.floor(x / <span class="hljs-number">13</span>);
        <span class="hljs-keyword">return</span> { suit: suits[pickedSuit], card: x % <span class="hljs-number">13</span> };
    }
}

<span class="hljs-keyword">let</span> myDeck = [{ suit: <span class="hljs-string">&quot;diamonds&quot;</span>, card: <span class="hljs-number">2</span> }, { suit: <span class="hljs-string">&quot;spades&quot;</span>, card: <span class="hljs-number">10</span> }, { suit: <span class="hljs-string">&quot;hearts&quot;</span>, card: <span class="hljs-number">4</span> }];
<span class="hljs-keyword">let</span> pickedCard1 = myDeck[pickCard(myDeck)];
alert(<span class="hljs-string">&quot;card: &quot;</span> + pickedCard1.card + <span class="hljs-string">&quot; of &quot;</span> + pickedCard1.suit);

<span class="hljs-keyword">let</span> pickedCard2 = pickCard(<span class="hljs-number">15</span>);
alert(<span class="hljs-string">&quot;card: &quot;</span> + pickedCard2.card + <span class="hljs-string">&quot; of &quot;</span> + pickedCard2.suit);
</code></pre>
<p>&#x8FD9;&#x6837;&#x6539;&#x53D8;&#x540E;&#xFF0C;&#x91CD;&#x8F7D;&#x7684;<code>pickCard</code>&#x51FD;&#x6570;&#x5728;&#x8C03;&#x7528;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x8FDB;&#x884C;&#x6B63;&#x786E;&#x7684;&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x8BA9;&#x7F16;&#x8BD1;&#x5668;&#x80FD;&#x591F;&#x9009;&#x62E9;&#x6B63;&#x786E;&#x7684;&#x68C0;&#x67E5;&#x7C7B;&#x578B;&#xFF0C;&#x5B83;&#x4E0E;JavaScript&#x91CC;&#x7684;&#x5904;&#x7406;&#x6D41;&#x7A0B;&#x76F8;&#x4F3C;&#x3002;
&#x5B83;&#x67E5;&#x627E;&#x91CD;&#x8F7D;&#x5217;&#x8868;&#xFF0C;&#x5C1D;&#x8BD5;&#x4F7F;&#x7528;&#x7B2C;&#x4E00;&#x4E2A;&#x91CD;&#x8F7D;&#x5B9A;&#x4E49;&#x3002;
&#x5982;&#x679C;&#x5339;&#x914D;&#x7684;&#x8BDD;&#x5C31;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x3002;
&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x5B9A;&#x4E49;&#x91CD;&#x8F7D;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x628A;&#x6700;&#x7CBE;&#x786E;&#x7684;&#x5B9A;&#x4E49;&#x653E;&#x5728;&#x6700;&#x524D;&#x9762;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;<code>function pickCard(x): any</code>&#x5E76;&#x4E0D;&#x662F;&#x91CD;&#x8F7D;&#x5217;&#x8868;&#x7684;&#x4E00;&#x90E8;&#x5206;&#xFF0C;&#x56E0;&#x6B64;&#x8FD9;&#x91CC;&#x53EA;&#x6709;&#x4E24;&#x4E2A;&#x91CD;&#x8F7D;&#xFF1A;&#x4E00;&#x4E2A;&#x662F;&#x63A5;&#x6536;&#x5BF9;&#x8C61;&#x53E6;&#x4E00;&#x4E2A;&#x63A5;&#x6536;&#x6570;&#x5B57;&#x3002;
&#x4EE5;&#x5176;&#x5B83;&#x53C2;&#x6570;&#x8C03;&#x7528;<code>pickCard</code>&#x4F1A;&#x4EA7;&#x751F;&#x9519;&#x8BEF;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Classes.html" class="navigation navigation-prev " aria-label="Previous page: 类">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Generics.html" class="navigation navigation-next " aria-label="Next page: 泛型">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"函数","level":"1.3.5","depth":2,"next":{"title":"泛型","level":"1.3.6","depth":2,"path":"doc/handbook/Generics.md","ref":"./doc/handbook/Generics.md","articles":[]},"previous":{"title":"类","level":"1.3.4","depth":2,"path":"doc/handbook/Classes.md","ref":"./doc/handbook/Classes.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Patrick Zhong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"preface.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"TypeScript Handbook","language":"zh-hans","gitbook":">3.0.0","description":"Translation of official TypeScript Handbook"},"file":{"path":"doc/handbook/Functions.md","mtime":"2018-10-13T09:48:54.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T09:57:42.904Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

